<%--
  Created by IntelliJ IDEA.
  User: 沐硕
  Date: 2024/3/25
  Time: 18:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %><!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <link rel="stylesheet" type="text/css" href="../layui-v2.9.10/layui/css/layui.css"/>
    <script src="../layui-v2.9.10/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .layui-container {
            margin-top: 50px;
        }
        .layui-form-item {
            margin-bottom: 20px;
        }
        .layui-btn {
            width: 100%;
        }
        .rounded-form-container {
            border: 1px solid #e6e6e6;
            border-radius: 10px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 20px;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="rounded-form-container">
        <div style="display: flex; align-items: center; margin: 5px 0px; justify-content: center;">
            <h2>用户注册</h2>
        </div>

        <div class="layui-row">
            <div class="layui-col-md6 layui-col-md-offset3">
                <form class="layui-form" action="../register.do" method="post" onsubmit="return validateForm()">
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="username">用户名：</label>
                        <div class="layui-input-block">
                            <input type="text" id="username" name="username" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="password">密码：</label>
                        <div class="layui-input-block">
                            <input type="password" id="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="password2">确认密码：</label>
                        <div class="layui-input-block">
                            <input type="password" id="password2" name="password2" required lay-verify="required" placeholder="请确认密码" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">用户类型：</label>
                        <div class="layui-input-block">
                            <input type="radio" id="buyer" name="user_type" value="0" title="买家" required>
                            <input type="radio" id="seller" name="user_type" value="1" title="卖家" required>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label" for="phone">电话：</label>
                        <div class="layui-input-block">
                            <input type="text" id="phone" name="phone" required lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label" for="email">电子邮件：</label>
                        <div class="layui-input-block">
                            <input type="email" id="email" name="email" required lay-verify="required" placeholder="请输入电子邮件" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button type="submit" class="layui-btn layui-btn-normal">立即注册</button>
                    </div>
                    <div class="layui-form-item layui-text-center">
                        <a href="login-2.jsp">已有账号？登录</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form;
        form.render();
    });

    function validateForm() {
        // 检查密码是否一致
        var password = document.getElementById("password").value;
        var password2 = document.getElementById("password2").value;
        if (password !== password2) {
            alert("两次输入的密码不一致，请重新输入。");
            return false;
        }

        // 检查电话号码格式
        var phone = document.getElementById("phone").value;
        var phonePattern = /^[1-10]\d{10}$/; // 假设电话号码为10位数字且不以0开头
        if (!phonePattern.test(phone)) {
            alert("请输入有效的电话号码。");
            return false;
        }

        // 检查电子邮件格式
        var email = document.getElementById("email").value;
        var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // 简单的电子邮件验证正则表达式
        if (!emailPattern.test(email)) {
            alert("请输入有效的电子邮件地址。");
            return false;
        }

        return true; // 如果所有验证通过，返回 true 以允许表单提交
    }
</script>
</body>
</html>
